package com.xingongchang.baolebei.activity;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.external.androidquery.callback.AjaxStatus;
import com.insthub.BeeFramework.model.BusinessResponse;
import com.xingongchang.baolebei.R;
import com.xingongchang.baolebei.model.ProtocolConst;
import com.xingongchang.baolebei.model.UserInfoModel;
import com.xingongchang.baolebei.protocol.SESSION;
import com.xingongchang.baolebei.protocol.USER_INFO;

public class Update_pwd extends  Activity implements BusinessResponse{
	private LinearLayout Update_right_button;
	private EditText editText1,editText2,editText3;
	private UserInfoModel mUserInfoModel;
	public USER_INFO userinfo;
	private ImageView fanhui;
	String m1,m2,m3;
	  @Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.update_pwd);
		findViewByid();
		mUserInfoModel = new UserInfoModel(this);
		mUserInfoModel.addResponseListener(this);
		SESSION session=SESSION.getInstance();
		mUserInfoModel.getTopicUserInfo(session.uid);
	}
	private void findViewByid() {
		Update_right_button=(LinearLayout) findViewById(R.id.Update_right_button);
		editText1=(EditText) findViewById(R.id.updateOne);
		editText2=(EditText) findViewById(R.id.updatetwo);
		editText3=(EditText) findViewById(R.id.updatethree);
		fanhui=(ImageView) findViewById(R.id.fanhui);
		fanhui.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				finish();
				overridePendingTransition(R.anim.push_right_in,
						R.anim.push_right_out);
			}
		});
		
		Update_right_button.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				m1=editText1.getText().toString().trim();
				m2=editText2.getText().toString().trim();
				m3=editText3.getText().toString().trim();
				if(!m3.equals(m2)){
					Toast.makeText(getApplicationContext(), "两次输入密码不一致", Toast.LENGTH_LONG).show();
//					Intent intent=new Intent(Update_pwd.this,Update_pwd.class);
//					startActivity(intent);
//					overridePendingTransition(R.anim.push_right_in,
//							R.anim.push_right_out);
					editText2.setText("");
					editText3.setText("");
					
				}else{
					mUserInfoModel.setUserPwd(m1, m2);
				}
			}
		});
	}
	@Override
	public void OnMessageResponse(String url, JSONObject jo, AjaxStatus status)
			throws JSONException {
		if(url.endsWith(ProtocolConst.EDIT_USER_INFO)){
			Toast.makeText(Update_pwd.this, "密码修改成功",
					Toast.LENGTH_SHORT).show();
			finish();
		}
	}
	
}
